#include "CallOnceTest.h"
#include<iostream>
#include<thread>
#include<mutex>
#include<chrono>

using namespace std;
using namespace com::example::testone::thread::mutex;

com::example::testone::thread::mutex::CallOnceTest::CallOnceTest()
{
    //ctor
}

com::example::testone::thread::mutex::CallOnceTest::~CallOnceTest()
{
    //dtor
}

void com::example::testone::thread::mutex::CallOnceTest::test(){
    this->test1();
}

void com::example::testone::thread::mutex::CallOnceTest::test1(){
    std::thread t1(&CallOnceTest::run, this);
    std::thread t2(&CallOnceTest::run, this);
    std::thread t3(&CallOnceTest::run, this);
    std::thread t4(&CallOnceTest::run, this);
    std::thread t5(&CallOnceTest::run, this);

    t1.join();
    t2.join();
    t3.join();
    t4.join();
    t5.join();

    std::cout << this->prop1 << std::endl;
}

void com::example::testone::thread::mutex::CallOnceTest::init_once(){
    std::cout << "CallOnceTest::init_once()........" << std::endl;
    this->prop1++;
}

void com::example::testone::thread::mutex::CallOnceTest::run(){
    std::call_once(this->mOnceFlag, &CallOnceTest::init_once, this);
}
